﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

namespace VSM
{
    public partial class Popup_TechnicalList : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string modelName = Request.QueryString["ModelName"] == null ? "" : Request.QueryString["ModelName"];
                LoadDataByModel(modelName);

                //string filePath = Server.MapPath("Technical");
                //string fileName = Request.QueryString["FullPath"] == null ? "" : Request.QueryString["FullPath"];
                //if (fileName.Length > 0)
                //{
                //    string fullPath = System.IO.Path.Combine(filePath, fileName);
                //    Response.AddHeader("Content-Disposition", "inline; filename=" + fullPath);
                //    Response.ContentType = "Application/pdf";
                //    Response.WriteFile(fullPath);
                //    Response.End();
                //}

            }
        }
        //RUKOWEN ADDED
        protected void grvPO_RowCreated(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.RowType == DataControlRowType.DataRow)
            //{
            //    GridViewRow myRow = e.Row;
            //    Label lblNo = myRow.FindControl("lblNo") as Label;
            //    lblNo.Text = (myRow.RowIndex + 1).ToString();
            //    //if (this.hdnStatus.Value == "C")
            //    //{
            //    //    TextBox txtQuantity = myRow.FindControl("txtOrderQuantity") as TextBox;
            //    //    txtQuantity.Enabled = false;
            //    //}
            //}
        }
        protected void grvSearchResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.grvPO.PageIndex = e.NewPageIndex;
          
        }
        private void LoadDataByModel(string ModelName)
        {
            if (ModelName.Length > 4)
            {
                string sql = "select ROW_NUMBER() OVER (ORDER BY BulletinID) AS No, BulletinID, BulletinName, bu.ModelCode, FilePath from U_Bulletin bu ";
                sql += "join U_Model mo on bu.ModelCode= mo.ModelCode ";
                sql += "where mo.ModelName like '%" + ModelName.Substring(0, 5) + "%' ";
                Services sv = new Services();
                Session["BulletinList"] = sv.ExecuteQuery("VSM", sql).Tables[0];
                grvPO.DataSource = (DataTable)Session["BulletinList"];
                grvPO.DataBind();
            }
        }

    }
}